class Solution {
public:
    string reverseWords(string s) {
        size_t start = 0;
        size_t end = s.find_first_of(' ', 0);
        while (end != string::npos)
        {
            reverse(s.begin() + start, s.begin() + end);
            start = end + 1;
            end = s.find_first_of(' ', end + 1);
        }
        reverse(s.begin() + start, s.end());
        return s;
    }
};